package com.ziroom.zifamily.zfcensor.logic;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>接入阿里云敏感词过滤，由基础平台提供接口</p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2018年12月03日 14:17
 * @since 1.0
 */
@Component
public class AntispamLogic {


    @Value("${ziroom.antispam.text-scan-url}")
    private String ziroomAntispamUrl;

    @Value("${ziroom.antispam.text-scan-url}")
    private String ziroomAntispamBizType;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 调用阿里云敏感词
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public String antispamTextScan(String text) {

        if (StringUtils.isEmpty(text)) {
            return null;
        }
        AntispamDTO antispamDTO = new AntispamDTO(ziroomAntispamBizType,text);
        String body = restTemplate.postForObject(ziroomAntispamUrl, antispamDTO, String.class);
        return body;
    }

    @Data
    @AllArgsConstructor
    class AntispamDTO {
        private String bizType;
        private String text;
    }
}
